<?php

$app->get('/test1', function (Request $request, Response $response) {
    return 'hello world';
});

// $app->group(['prefix' => 'user'], function () {
$app->get('/test', '\App\Http\Controllers\TestController:test');
$app->get('/index', '\App\Http\Controllers\TestController:index');
$app->post('/account', '\App\Http\Controllers\AccountController:store');
$app->post('/verify', '\App\Http\Controllers\VerifyController:store');
$app->post('/bucket', '\App\Http\Controllers\OSS\BucketController:exist');

$app->post('/user', '\App\Http\Controllers\User\UserController:test');


$app->group('/user', function () {

    $this->post('/token', '\App\Http\Controllers\User\TokenController:token');
    $this->post('/user', '\App\Http\Controllers\User\UserController:store');
    $this->put('/user', '\App\Http\Controllers\User\UserController:update');
    $this->post('/usertest', '\App\Http\Controllers\User\UserController:test');

})->add(new App\Middleware\UserJWT([
  "secure" => false,
  "path" => ["/"],
  "passthrough" => ['/user/token', 'user/user'],
  "secret" => getenv('JWT_USER_SECRET'),
  "algorithm" => ["HS256", "HS384"],
  "callback" => function ($request, $response, $args) use ($container) {
      $container["jwt"] = $args["decoded"];
   }
]));


$app->group('/admin', function () {

    $this->post('/token', '\App\Http\Controllers\Admin\TokenController:token');
    $this->post('/admin', '\App\Http\Controllers\Admin\AdminController:store');
    $this->get('/admin', '\App\Http\Controllers\Admin\AdminController:show');
    $this->post('/user', '\App\Http\Controllers\User\UserController:store');

})->add(new App\Middleware\AdminJWT([
  "secure" => false,
  "path" => ["/"],
  "passthrough" => ['/admin/token'],
  "secret" => getenv('JWT_ADMIN_SECRET'),
  "algorithm" => ["HS256", "HS384"],
  "callback" => function ($request, $response, $args) use ($container) {
      $container["jwt"] = $args["decoded"];
   }
]));
